import request from "@/api/request"
import { userInfoStore } from '@/store';

const userStore = userInfoStore();

export function getNameList(){
    return request({
        url: "/api/user/nameList",
        method: "get",
    })
}

export function getInfo(username){
    return request({
        url: '/api/user/userInfo',
        method: 'get',
        params: {
            username: username
        },
    }).then((info) => {
        userStore.setAll(info?.data);
    })
}

export function getUsersByAuth(auth){
    return request({
        url: '/api/user/userList',
        method: 'get',
        params: {
            auth: auth,
        },
    })
}

export function deleteById(userId){
    return request({
        url: '/api/user/delete/' + userId,
        method: 'delete',
    })
}

export function editByUserId(data){
    return request({
        url: '/api/user/edit',
        method: 'put',
        data: data,
        headers: "Content-Type:application/json",
    })
}

export function editByUsername(data){
    return request({
        url: '/api/user/editByUsername',
        method: 'put',
        data: data,
        headers: "Content-Type:application/json",
    })
}

export function addUser(data){
    return request({
        url: '/api/user/add',
        method: 'post',
        data: data,
        headers: "Content-Type:application/json",
    })
}